package com.home.ex;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Topics模式
 * @author ：G
 */
@Configuration
public class RabbitmqConfigTopics {
    //定义消息队列的名字
    public static final String QUEUE_TOPIC_1 = "topic_queue1";
    public static final String QUEUE_TOPIC_2 = "topic_queue2";
    public static final String EXCHANGE_TOPIC = "exchnage-topic";
    @Bean
    public Exchange topicexchange(){
        //定义一个direct类型的交换机，并指定持久化
        return ExchangeBuilder.topicExchange(EXCHANGE_TOPIC).durable(true).build();
    }

    @Bean
    public Queue topicqueue1() {
        //创建一个队列队列，并指定队列的名字
        return new Queue(QUEUE_TOPIC_1,true);
    }

    @Bean
    public Queue topicqueue2() {
        //创建一个队列队列，并指定队列的名字
        return new Queue( QUEUE_TOPIC_2,true);
    }

    @Bean
    public Binding topicbindingQueue1() {
        return BindingBuilder
                .bind(topicqueue1()).to(topicexchange()).with("pay.#").noargs();
    }
    @Bean
    public Binding topicbindingQueue2() {
        return BindingBuilder
                .bind(topicqueue2()).to(topicexchange()).with("order.#").noargs();
    }
}
